package com.LFLWZ.serviceImpl;

import com.LFLWZ.beans.Dto.adminListQuery;
import com.LFLWZ.beans.POJO.*;
import com.LFLWZ.beans.Vo.ClassroomCourseVo;
import com.LFLWZ.beans.Vo.CourseByType;
import com.LFLWZ.beans.Vo.UserlogSheet;
import com.LFLWZ.beans.Vo.addLike;
import com.LFLWZ.mapper.ClassroomCourseMapper;
import com.LFLWZ.mapper.CourseColumnMapper;
import com.LFLWZ.service.ClassroomCourseService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * (ClassroomCourse)表服务实现类
 *
 * @author lujum
 * @since 2020-12-03 01:41:26
 */
@Service
public class ClassroomCourseServiceImpl implements ClassroomCourseService {

    @Autowired
    private ClassroomCourseMapper classroomCourseDao;
    @Autowired
    private CourseColumnMapper courseColumnMapper;
    @Override
    public List<ClassroomCourse> selByStudyNumber() {
        return classroomCourseDao.selByStudyNumber();
    }

    @Override
    public List<UserlogSheet> selLog(Integer uid) {
        return classroomCourseDao.selLog(uid);
    }

    @Override
    public List<CourseFiltrate> selCourse_filtrate(Integer filtrate) {
        return classroomCourseDao.selCourse_filtrate(filtrate);
    }

    @Override
    public List<filtrate> sel_filtrate() {
        return classroomCourseDao.sel_filtrate();
    }




    @Override
    public List<ClassroomCourse> selFiltrate(CourseByType courseByType) {
        Integer offset = (courseByType.getPage() - 1) * courseByType.getSize();
        return classroomCourseDao.selFiltrate(courseByType, offset, courseByType.getSize());
    }

    @Override
    public List<ClassroomCourse> selByUid(Integer uid) {
        return classroomCourseDao.selByUid(uid,1);
    }

    @Override
    public List<ClassroomCourse> selByLecture(Integer uid) {
        return classroomCourseDao.selByLecture(uid);
    }


    @Override
    public List<CourseType> selCourseType(CourseType courseType) {
        return classroomCourseDao.selCourseType(courseType);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ClassroomCourseVo queryById(Integer id) {
        return classroomCourseDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<ClassroomCourse> queryAllByLimit(int offset, int limit) {
        return this.classroomCourseDao.queryAllByLimit(new adminListQuery());
    }

    /**
     * 新增数据
     *
     * @param classroomCourse 实例对象
     * @return 实例对象
     */
    @Override
    public ClassroomCourseVo insert(ClassroomCourseVo classroomCourse) {
        this.classroomCourseDao.insert(classroomCourse);
        CourseFiltrate courseFiltrate=new CourseFiltrate();
        courseFiltrate.setCourseId(classroomCourse.getId());
        courseFiltrate.setFiltrateId(classroomCourse.getCid());
        classroomCourseDao.inFiltrate(courseFiltrate);
        CourseColumn courseColumn=new CourseColumn(classroomCourse.getId(),classroomCourse.getSid());
        courseColumnMapper.insert(courseColumn);
        return classroomCourse;
    }

    /**
     * 修改数据
     *
     * @param classroomCourse 实例对象
     * @return 实例对象
     */
    @Override
    public ClassroomCourseVo update(ClassroomCourseVo classroomCourse) {
        CourseFiltrate courseFiltrate=new CourseFiltrate();
        courseFiltrate.setCourseId(classroomCourse.getId());
        CourseFiltrate courseFiltrate1= classroomCourseDao.selByFiltrate(courseFiltrate);
        courseFiltrate1.setFiltrateId(classroomCourse.getCid());
        classroomCourseDao.upFiltrate(courseFiltrate1);
        CourseColumn courseColumn=new CourseColumn(classroomCourse.getId());
        List<CourseColumn> courses= courseColumnMapper.queryAll(courseColumn);
        courses.get(0).setColumnid(classroomCourse.getSid());
        courseColumnMapper.update(courses.get(0));
        this.classroomCourseDao.update(classroomCourse);


        return this.queryById(classroomCourse.getId());
    }

    @Override
    public Boolean updateScore(ClassroomCourseVo classroomCourse){
        int i=classroomCourseDao.update(classroomCourse);
        return i>0;
    }
    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        courseColumnMapper.deleteById(id);
        classroomCourseDao.deFiltrate(id);
        return this.classroomCourseDao.deleteById(id) > 0;
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param
     * @return 对象列表
     */
    @Override
    public List<ClassroomCourse> queryAll(Integer id) {
        List<ClassroomCourse> list = new ArrayList<>();
        ClassroomCourse c = new ClassroomCourse();
        c.setStatus(1);
        if (id == 0) {
            list = classroomCourseDao.queryAll(c);
        } else {
            String a=id.toString();
            System.out.println(a);
            c.setTypeId(a);
           list=classroomCourseDao.queryAll(c);
        }
        return list;
    }


    /**
     * 对比两个元素剔除相同的元素
     *
     * @param courses1
     * @param courses2
     * @return
     */
    public List<ClassroomCourse> ContranstDifferentia(List<ClassroomCourse> courses1, List<ClassroomCourse> courses2) {
//        if (hashSet.add(c.getCourseId())) {
//            courses.add(classroomCourseService.queryById(c.getCourseId()));
//        }
        return null;
    }
}